//
//  assetsViewController.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/6.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "assetsViewController.h"
#import "DWTabView.h"
#import "DWPageViewController.h"
#import "assetsAViewController.h"
#import "assetsOViewController.h"
#import "taskOverviewService.h"

//AssetsTopView
@interface assetsViewController ()<BMPageViewControllerDelegate>
@property (nonatomic,strong) UIView *pageContentView;
@property (nonatomic,strong)    DWTabView   *tabView;
@property (nonatomic,strong)dataOverCoinInfo *coinModel;
@property (nonatomic,strong)UILabel  *lbcoin;  /**<    */
///当前类型
@property (nonatomic,assign)    BOOL  isChinaA;
@end

@implementation assetsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.isChinaA = YES;
    [self changeHeadView];
    [self initUI];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if (@available(iOS 11.0, *)) {
        UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    [self setBlackStatus:NO];
    
    self.hidesBottomBarWhenPushed = NO;
    if (self.tabBarController.tabBar.hidden == YES) {
        self.tabBarController.tabBar.hidden = NO;
    }
    if (self.navigationController.navigationBar.hidden == NO) {
        self.navigationController.navigationBar.hidden = YES;
    }
}


-(void)initUI{
    self.tabView = [[DWTabView alloc]initWithFrame:CGRectMake((KScreenWidth - 140)/2, 40, 140, 24)];
    self.tabView.selectColor = COLOR_main;
    self.tabView.normalColor = [UIColor whiteColor];
    self.tabView.items = @[@"china-A",@"其它资产"];
    self.tabView.indicatorPosition = BMTabViewIndicatorPoistionBottom;
    [self.view addSubview:_tabView];
    _pageContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 200, KScreenWidth, KScreenHeight - 200)];
    [self.view addSubview:_pageContentView];
    DWPageViewController *pageVC = [[DWPageViewController alloc] initWithViewControllers:@[[assetsAViewController new], [assetsOViewController new]]];
    pageVC.delegate = self;
    [self addViewController:pageVC];
    self.tabView.selection = ^(NSUInteger index, NSUInteger oldIndex) {
        pageVC.selectIndex = (unsigned int)index;
    };
    self.lbcoin.text = [NSString stringWithFormat:@"%.2f",[[UserCenter shareCenter].user.Balance floatValue]];
    [self.view addSubview:self.lbcoin];
    UILabel *lbtitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, KScreenWidth, 20)];
    lbtitle.textColor = [UIColor whiteColor];
    lbtitle.text = @"总资产";
    lbtitle.font = [UIFont systemFontOfSize:13];
    lbtitle.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:lbtitle];
}

- (void)addViewController:(UIViewController *)pageVC
{
    [self addChildViewController:pageVC];
    [self.pageContentView addSubview:pageVC.view];
    [pageVC didMoveToParentViewController:self];
}

- (void)pageViewController:(DWPageViewController *)pageViewController didScrollToIndex:(int)index
{
    self.tabView.selectedIndex = index;
}

- (void)pageViewController:(DWPageViewController *)pageViewController didScrollBetweenIndex1:(int)index1 index2:(int)index2 withPercent:(CGFloat)percent
{
    [self.tabView scrollIndicatorBetweenIndex1:index1 index2:index2 withPercent:percent];
}

-(UILabel *)lbcoin
{
    if (!_lbcoin) {
        _lbcoin = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, KScreenWidth, 15)];
        _lbcoin.textColor = [UIColor whiteColor];
        _lbcoin.font = [UIFont systemFontOfSize:13];
        _lbcoin.textAlignment = NSTextAlignmentCenter;
    }
    return _lbcoin;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
